package com.liu.stockmarket

import android.app.Application
import android.util.Log
import com.liu.stockmarket.repository.database.MyRoomDataBase
import com.liu.stockmarket.repository.database.ProfitRepository
import com.liu.stockmarket.repository.database.StockRepository
import com.liu.stockmarket.repository.database.TransactionRecordRepository
import com.liu.stockmarket.repository.database.entity.StockEntity
import com.liu.stockmarket.repository.network.EasyMoneyRepository
import com.lxj.xpopup.XPopup
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob

class StockMarketApplication : Application() {
    private val applicationScope = CoroutineScope(SupervisorJob())

    private val database by lazy { MyRoomDataBase.getDatabase(this, applicationScope) }

    val stockRepository by lazy {
        StockRepository(database.stockDao(), database.transactionRecordDao())
    }

    val transactionRecordRepository by lazy {
        TransactionRecordRepository(database.transactionRecordDao())
    }


    val easyMoneyRepository by lazy {
        EasyMoneyRepository()
    }

    val profitRepository by lazy {
        ProfitRepository(database.profitDao())
    }

    override fun onCreate() {
        super.onCreate()
        Log.i(this.javaClass.name, "启动应用交易记录")
        XPopup.setPrimaryColor(getColor(R.color.color_primary));
        database.query("select id from room_master_table limit 1 ", null)

    }
}